<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>V8 | Node.js v8.12.0 Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/v8.html">
</head>
<body class="alt apidoc" id="api-section-v8">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-async_hooks" href="async_hooks.html">Async Hooks</a></li>
<li><a class="nav-buffer" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C++ Addons</a></li>
<li><a class="nav-n-api" href="n-api.html">C/C++ Addons - N-API</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-deprecations" href="deprecations.html">Deprecated APIs</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-esm" href="esm.html">ECMAScript Modules</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-http2" href="http2.html">HTTP/2</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-inspector" href="inspector.html">Inspector</a></li>
<li><a class="nav-intl" href="intl.html">Internationalization</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-perf_hooks" href="perf_hooks.html">Performance Hooks</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tracing" href="tracing.html">Tracing</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8 active" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-https-groups-google-com-group-nodejs" href="https://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="v8" class="interior">
      <header>
        <h1>Node.js v8.12.0 Documentation</h1>
        <div id="gtoc">
          <ul>
            <li>
              <a href="index.html" name="toc">Index</a>
            </li>
            <li>
              <a href="all.html">View on single page</a>
            </li>
            <li>
              <a href="v8.json">View as JSON</a>
            </li>
            
    <li class="version-picker">
      <a href="#">View another version <span>&#x25bc;</span></a>
      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v9.x/api/v8.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/v8.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/v8.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/v8.html">6.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/v8.html">5.x</a></li></ol>
    </li>
  
          </ul>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><span class="stability_undefined"><a href="#v8_v8">V8</a></span><ul>
<li><span class="stability_undefined"><a href="#v8_v8_cacheddataversiontag">v8.cachedDataVersionTag()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_getheapspacestatistics">v8.getHeapSpaceStatistics()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_getheapstatistics">v8.getHeapStatistics()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_setflagsfromstring_string">v8.setFlagsFromString(string)</a></span></li>
<li><span class="stability_1"><a href="#v8_serialization_api">Serialization API</a></span><ul>
<li><span class="stability_undefined"><a href="#v8_v8_serialize_value">v8.serialize(value)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_v8_deserialize_buffer">v8.deserialize(buffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_class_v8_serializer">class: v8.Serializer</a></span><ul>
<li><span class="stability_undefined"><a href="#v8_new_serializer">new Serializer()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writeheader">serializer.writeHeader()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writevalue_value">serializer.writeValue(value)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_releasebuffer">serializer.releaseBuffer()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_transferarraybuffer_id_arraybuffer">serializer.transferArrayBuffer(id, arrayBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writeuint32_value">serializer.writeUint32(value)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writeuint64_hi_lo">serializer.writeUint64(hi, lo)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writedouble_value">serializer.writeDouble(value)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writerawbytes_buffer">serializer.writeRawBytes(buffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_writehostobject_object">serializer._writeHostObject(object)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_getdatacloneerror_message">serializer._getDataCloneError(message)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer">serializer._getSharedArrayBufferId(sharedArrayBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_serializer_settreatarraybufferviewsashostobjects_flag">serializer._setTreatArrayBufferViewsAsHostObjects(flag)</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#v8_class_v8_deserializer">class: v8.Deserializer</a></span><ul>
<li><span class="stability_undefined"><a href="#v8_new_deserializer_buffer">new Deserializer(buffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readheader">deserializer.readHeader()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readvalue">deserializer.readValue()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_transferarraybuffer_id_arraybuffer">deserializer.transferArrayBuffer(id, arrayBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_getwireformatversion">deserializer.getWireFormatVersion()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readuint32">deserializer.readUint32()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readuint64">deserializer.readUint64()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readdouble">deserializer.readDouble()</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readrawbytes_length">deserializer.readRawBytes(length)</a></span></li>
<li><span class="stability_undefined"><a href="#v8_deserializer_readhostobject">deserializer._readHostObject()</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#v8_class_v8_defaultserializer">class: v8.DefaultSerializer</a></span></li>
<li><span class="stability_undefined"><a href="#v8_class_v8_defaultdeserializer">class: v8.DefaultDeserializer</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>V8<span><a class="mark" href="#v8_v8" id="v8_v8">#</a></span></h1>
<!--introduced_in=v4.0.0-->
<p>The <code>v8</code> module exposes APIs that are specific to the version of <a href="https://developers.google.com/v8/">V8</a>
built into the Node.js binary. It can be accessed using:</p>
<pre><code class="lang-js">const v8 = require(&#39;v8&#39;);
</code></pre>
<p><em>Note</em>: The APIs and implementation are subject to change at any time.</p>
<h2>v8.cachedDataVersionTag()<span><a class="mark" href="#v8_v8_cacheddataversiontag" id="v8_v8_cacheddataversiontag">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v8.0.0</span>
</div><p>Returns an integer representing a &quot;version tag&quot; derived from the V8 version,
command line flags and detected CPU features. This is useful for determining
whether a <a href="vm.html#vm_new_vm_script_code_options"><code>vm.Script</code></a> <code>cachedData</code> buffer is compatible with this instance
of V8.</p>
<h2>v8.getHeapSpaceStatistics()<span><a class="mark" href="#v8_v8_getheapspacestatistics" id="v8_v8_getheapspacestatistics">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v7.5.0</td>
<td><p>Support values exceeding the 32-bit unsigned integer range.</p>
</td></tr>
<tr><td>v6.0.0</td>
<td><p><span>Added in: v6.0.0</span></p>
</td></tr>
</table>
</details>
</div><p>Returns statistics about the V8 heap spaces, i.e. the segments which make up
the V8 heap. Neither the ordering of heap spaces, nor the availability of a
heap space can be guaranteed as the statistics are provided via the V8
<a href="https://v8docs.nodesource.com/node-8.0/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4"><code>GetHeapSpaceStatistics</code></a> function and may change from one V8 version to the
next.</p>
<p>The value returned is an array of objects containing the following properties:</p>
<ul>
<li><code>space_name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>space_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>space_used_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>space_available_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>physical_space_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
<p>For example:</p>
<pre><code class="lang-json">[
  {
    &quot;space_name&quot;: &quot;new_space&quot;,
    &quot;space_size&quot;: 2063872,
    &quot;space_used_size&quot;: 951112,
    &quot;space_available_size&quot;: 80824,
    &quot;physical_space_size&quot;: 2063872
  },
  {
    &quot;space_name&quot;: &quot;old_space&quot;,
    &quot;space_size&quot;: 3090560,
    &quot;space_used_size&quot;: 2493792,
    &quot;space_available_size&quot;: 0,
    &quot;physical_space_size&quot;: 3090560
  },
  {
    &quot;space_name&quot;: &quot;code_space&quot;,
    &quot;space_size&quot;: 1260160,
    &quot;space_used_size&quot;: 644256,
    &quot;space_available_size&quot;: 960,
    &quot;physical_space_size&quot;: 1260160
  },
  {
    &quot;space_name&quot;: &quot;map_space&quot;,
    &quot;space_size&quot;: 1094160,
    &quot;space_used_size&quot;: 201608,
    &quot;space_available_size&quot;: 0,
    &quot;physical_space_size&quot;: 1094160
  },
  {
    &quot;space_name&quot;: &quot;large_object_space&quot;,
    &quot;space_size&quot;: 0,
    &quot;space_used_size&quot;: 0,
    &quot;space_available_size&quot;: 1490980608,
    &quot;physical_space_size&quot;: 0
  }
]
</code></pre>
<h2>v8.getHeapStatistics()<span><a class="mark" href="#v8_v8_getheapstatistics" id="v8_v8_getheapstatistics">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tr><th>Version</th><th>Changes</th></tr>
<tr><td>v7.5.0</td>
<td><p>Support values exceeding the 32-bit unsigned integer range.</p>
</td></tr>
<tr><td>v7.2.0</td>
<td><p>Added <code>malloced_memory</code>, <code>peak_malloced_memory</code>, and <code>does_zap_garbage</code>.</p>
</td></tr>
<tr><td>v1.0.0</td>
<td><p><span>Added in: v1.0.0</span></p>
</td></tr>
</table>
</details>
</div><p>Returns an object with the following properties:</p>
<ul>
<li><code>total_heap_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>total_heap_size_executable</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>total_physical_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>total_available_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>used_heap_size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>heap_size_limit</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>malloced_memory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>peak_malloced_memory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>does_zap_garbage</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
<p><code>does_zap_garbage</code> is a 0/1 boolean, which signifies whether the <code>--zap_code_space</code>
option is enabled or not. This makes V8 overwrite heap garbage with a bit
pattern. The RSS footprint (resident memory set) gets bigger because it
continuously touches all heap pages and that makes them less likely to get
swapped out by the operating system.</p>
<p>For example:</p>
<!-- eslint-skip -->
<pre><code class="lang-js">{
  total_heap_size: 7326976,
  total_heap_size_executable: 4194304,
  total_physical_size: 7326976,
  total_available_size: 1152656,
  used_heap_size: 3476208,
  heap_size_limit: 1535115264,
  malloced_memory: 16384,
  peak_malloced_memory: 1127496,
  does_zap_garbage: 0
}
</code></pre>
<h2>v8.setFlagsFromString(string)<span><a class="mark" href="#v8_v8_setflagsfromstring_string" id="v8_v8_setflagsfromstring_string">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><p>The <code>v8.setFlagsFromString()</code> method can be used to programmatically set
V8 command line flags. This method should be used with care. Changing settings
after the VM has started may result in unpredictable behavior, including
crashes and data loss; or it may simply do nothing.</p>
<p>The V8 options available for a version of Node.js may be determined by running
<code>node --v8-options</code>. An unofficial, community-maintained list of options
and their effects is available <a href="https://github.com/thlorenz/v8-flags/blob/master/flags-0.11.md">here</a>.</p>
<p>Usage:</p>
<pre><code class="lang-js">// Print GC events to stdout for one minute.
const v8 = require(&#39;v8&#39;);
v8.setFlagsFromString(&#39;--trace_gc&#39;);
setTimeout(function() { v8.setFlagsFromString(&#39;--notrace_gc&#39;); }, 60e3);
</code></pre>
<h2>Serialization API<span><a class="mark" href="#v8_serialization_api" id="v8_serialization_api">#</a></span></h2>
<div class="api_stability api_stability_1"><a href="documentation.html#documentation_stability_index">Stability: 1</a> - Experimental</div><p>The serialization API provides means of serializing JavaScript values in a way
that is compatible with the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">HTML structured clone algorithm</a>.
The format is backward-compatible (i.e. safe to store to disk).</p>
<p><em>Note</em>: This API is under development, and changes (including incompatible
changes to the API or wire format) may occur until this warning is removed.</p>
<h3>v8.serialize(value)<span><a class="mark" href="#v8_v8_serialize_value" id="v8_v8_serialize_value">#</a></span></h3>
<!--
added: v8.0.0
-->
<ul>
<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
<p>Uses a <a href="#v8_class_v8_defaultserializer"><code>DefaultSerializer</code></a> to serialize <code>value</code> into a buffer.</p>
<h3>v8.deserialize(buffer)<span><a class="mark" href="#v8_v8_deserialize_buffer" id="v8_v8_deserialize_buffer">#</a></span></h3>
<!--
added: v8.0.0
-->
<ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a> A buffer returned by <a href="#v8_v8_serialize_value"><code>serialize()</code></a>.</li>
</ul>
<p>Uses a <a href="#v8_class_v8_defaultdeserializer"><code>DefaultDeserializer</code></a> with default options to read a JS value
from a buffer.</p>
<h3>class: v8.Serializer<span><a class="mark" href="#v8_class_v8_serializer" id="v8_class_v8_serializer">#</a></span></h3>
<!--
added: v8.0.0
-->
<h4>new Serializer()<span><a class="mark" href="#v8_new_serializer" id="v8_new_serializer">#</a></span></h4>
<p>Creates a new <code>Serializer</code> object.</p>
<h4>serializer.writeHeader()<span><a class="mark" href="#v8_serializer_writeheader" id="v8_serializer_writeheader">#</a></span></h4>
<p>Writes out a header, which includes the serialization format version.</p>
<h4>serializer.writeValue(value)<span><a class="mark" href="#v8_serializer_writevalue_value" id="v8_serializer_writevalue_value">#</a></span></h4>
<p>Serializes a JavaScript value and adds the serialized representation to the
internal buffer.</p>
<p>This throws an error if <code>value</code> cannot be serialized.</p>
<h4>serializer.releaseBuffer()<span><a class="mark" href="#v8_serializer_releasebuffer" id="v8_serializer_releasebuffer">#</a></span></h4>
<p>Returns the stored internal buffer. This serializer should not be used once
the buffer is released. Calling this method results in undefined behavior
if a previous write has failed.</p>
<h4>serializer.transferArrayBuffer(id, arrayBuffer)<span><a class="mark" href="#v8_serializer_transferarraybuffer_id_arraybuffer" id="v8_serializer_transferarraybuffer_id_arraybuffer">#</a></span></h4>
<div class="signature"><ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> A 32-bit unsigned integer.</li>
<li><code>arrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&lt;ArrayBuffer&gt;</a> An <code>ArrayBuffer</code> instance.</li>
</ul>
</div><p>Marks an <code>ArrayBuffer</code> as havings its contents transferred out of band.
Pass the corresponding <code>ArrayBuffer</code> in the deserializing context to
<a href="#v8_deserializer_transferarraybuffer_id_arraybuffer"><code>deserializer.transferArrayBuffer()</code></a>.</p>
<h4>serializer.writeUint32(value)<span><a class="mark" href="#v8_serializer_writeuint32_value" id="v8_serializer_writeuint32_value">#</a></span></h4>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a></li>
</ul>
</div><p>Write a raw 32-bit unsigned integer.
For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
<h4>serializer.writeUint64(hi, lo)<span><a class="mark" href="#v8_serializer_writeuint64_hi_lo" id="v8_serializer_writeuint64_hi_lo">#</a></span></h4>
<div class="signature"><ul>
<li><code>hi</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a></li>
<li><code>lo</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a></li>
</ul>
</div><p>Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
<h4>serializer.writeDouble(value)<span><a class="mark" href="#v8_serializer_writedouble_value" id="v8_serializer_writedouble_value">#</a></span></h4>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
</div><p>Write a JS <code>number</code> value.
For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
<h4>serializer.writeRawBytes(buffer)<span><a class="mark" href="#v8_serializer_writerawbytes_buffer" id="v8_serializer_writerawbytes_buffer">#</a></span></h4>
<div class="signature"><ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a></li>
</ul>
</div><p>Write raw bytes into the serializer’s internal buffer. The deserializer
will require a way to compute the length of the buffer.
For use inside of a custom <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
<h4>serializer._writeHostObject(object)<span><a class="mark" href="#v8_serializer_writehostobject_object" id="v8_serializer_writehostobject_object">#</a></span></h4>
<div class="signature"><ul>
<li><code>object</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</div><p>This method is called to write some kind of host object, i.e. an object created
by native C++ bindings. If it is not possible to serialize <code>object</code>, a suitable
exception should be thrown.</p>
<p>This method is not present on the <code>Serializer</code> class itself but can be provided
by subclasses.</p>
<h4>serializer._getDataCloneError(message)<span><a class="mark" href="#v8_serializer_getdatacloneerror_message" id="v8_serializer_getdatacloneerror_message">#</a></span></h4>
<div class="signature"><ul>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
</div><p>This method is called to generate error objects that will be thrown when an
object can not be cloned.</p>
<p>This method defaults to the <a href="errors.html#errors_class_error"><code>Error</code></a> constructor and can be overridden on
subclasses.</p>
<h4>serializer._getSharedArrayBufferId(sharedArrayBuffer)<span><a class="mark" href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer" id="v8_serializer_getsharedarraybufferid_sharedarraybuffer">#</a></span></h4>
<div class="signature"><ul>
<li><code>sharedArrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer" class="type">&lt;SharedArrayBuffer&gt;</a></li>
</ul>
</div><p>This method is called when the serializer is going to serialize a
<code>SharedArrayBuffer</code> object. It must return an unsigned 32-bit integer ID for
the object, using the same ID if this <code>SharedArrayBuffer</code> has already been
serialized. When deserializing, this ID will be passed to
<a href="#v8_deserializer_transferarraybuffer_id_arraybuffer"><code>deserializer.transferArrayBuffer()</code></a>.</p>
<p>If the object cannot be serialized, an exception should be thrown.</p>
<p>This method is not present on the <code>Serializer</code> class itself but can be provided
by subclasses.</p>
<h4>serializer._setTreatArrayBufferViewsAsHostObjects(flag)<span><a class="mark" href="#v8_serializer_settreatarraybufferviewsashostobjects_flag" id="v8_serializer_settreatarraybufferviewsashostobjects_flag">#</a></span></h4>
<div class="signature"><ul>
<li><code>flag</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <strong>Default:</strong> <code>false</code></li>
</ul>
</div><p>Indicate whether to treat <code>TypedArray</code> and <code>DataView</code> objects as
host objects, i.e. pass them to <a href="#v8_serializer_writehostobject_object"><code>serializer._writeHostObject()</code></a>.</p>
<h3>class: v8.Deserializer<span><a class="mark" href="#v8_class_v8_deserializer" id="v8_class_v8_deserializer">#</a></span></h3>
<!--
added: v8.0.0
-->
<h4>new Deserializer(buffer)<span><a class="mark" href="#v8_new_deserializer_buffer" id="v8_new_deserializer_buffer">#</a></span></h4>
<div class="signature"><ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a> A buffer returned by <a href="#v8_serializer_releasebuffer"><code>serializer.releaseBuffer()</code></a>.</li>
</ul>
</div><p>Creates a new <code>Deserializer</code> object.</p>
<h4>deserializer.readHeader()<span><a class="mark" href="#v8_deserializer_readheader" id="v8_deserializer_readheader">#</a></span></h4>
<p>Reads and validates a header (including the format version).
May, for example, reject an invalid or unsupported wire format. In that case,
an <code>Error</code> is thrown.</p>
<h4>deserializer.readValue()<span><a class="mark" href="#v8_deserializer_readvalue" id="v8_deserializer_readvalue">#</a></span></h4>
<p>Deserializes a JavaScript value from the buffer and returns it.</p>
<h4>deserializer.transferArrayBuffer(id, arrayBuffer)<span><a class="mark" href="#v8_deserializer_transferarraybuffer_id_arraybuffer" id="v8_deserializer_transferarraybuffer_id_arraybuffer">#</a></span></h4>
<div class="signature"><ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> A 32-bit unsigned integer.</li>
<li><code>arrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&lt;ArrayBuffer&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer" class="type">&lt;SharedArrayBuffer&gt;</a> An <code>ArrayBuffer</code> instance.</li>
</ul>
</div><p>Marks an <code>ArrayBuffer</code> as havings its contents transferred out of band.
Pass the corresponding <code>ArrayBuffer</code> in the serializing context to
<a href="#v8_serializer_transferarraybuffer_id_arraybuffer"><code>serializer.transferArrayBuffer()</code></a> (or return the <code>id</code> from
<a href="#v8_serializer_getsharedarraybufferid_sharedarraybuffer"><code>serializer._getSharedArrayBufferId()</code></a> in the case of <code>SharedArrayBuffer</code>s).</p>
<h4>deserializer.getWireFormatVersion()<span><a class="mark" href="#v8_deserializer_getwireformatversion" id="v8_deserializer_getwireformatversion">#</a></span></h4>
<div class="signature"><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a></li>
</ul>
</div><p>Reads the underlying wire format version. Likely mostly to be useful to
legacy code reading old wire format versions. May not be called before
<code>.readHeader()</code>.</p>
<h4>deserializer.readUint32()<span><a class="mark" href="#v8_deserializer_readuint32" id="v8_deserializer_readuint32">#</a></span></h4>
<div class="signature"><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a></li>
</ul>
</div><p>Read a raw 32-bit unsigned integer and return it.
For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
<h4>deserializer.readUint64()<span><a class="mark" href="#v8_deserializer_readuint64" id="v8_deserializer_readuint64">#</a></span></h4>
<div class="signature"><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>
</ul>
</div><p>Read a raw 64-bit unsigned integer and return it as an array <code>[hi, lo]</code>
with two 32-bit unsigned integer entries.
For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
<h4>deserializer.readDouble()<span><a class="mark" href="#v8_deserializer_readdouble" id="v8_deserializer_readdouble">#</a></span></h4>
<div class="signature"><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
</ul>
</div><p>Read a JS <code>number</code> value.
For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
<h4>deserializer.readRawBytes(length)<span><a class="mark" href="#v8_deserializer_readrawbytes_length" id="v8_deserializer_readrawbytes_length">#</a></span></h4>
<div class="signature"><ul>
<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
</div><p>Read raw bytes from the deserializer’s internal buffer. The <code>length</code> parameter
must correspond to the length of the buffer that was passed to
<a href="#v8_serializer_writerawbytes_buffer"><code>serializer.writeRawBytes()</code></a>.
For use inside of a custom <a href="#v8_deserializer_readhostobject"><code>deserializer._readHostObject()</code></a>.</p>
<h4>deserializer._readHostObject()<span><a class="mark" href="#v8_deserializer_readhostobject" id="v8_deserializer_readhostobject">#</a></span></h4>
<p>This method is called to read some kind of host object, i.e. an object that is
created by native C++ bindings. If it is not possible to deserialize the data,
a suitable exception should be thrown.</p>
<p>This method is not present on the <code>Deserializer</code> class itself but can be
provided by subclasses.</p>
<h3>class: v8.DefaultSerializer<span><a class="mark" href="#v8_class_v8_defaultserializer" id="v8_class_v8_defaultserializer">#</a></span></h3>
<!--
added: v8.0.0
-->
<p>A subclass of <a href="#v8_class_v8_serializer"><code>Serializer</code></a> that serializes <code>TypedArray</code>
(in particular <a href="buffer.html"><code>Buffer</code></a>) and <code>DataView</code> objects as host objects, and only
stores the part of their underlying <code>ArrayBuffer</code>s that they are referring to.</p>
<h3>class: v8.DefaultDeserializer<span><a class="mark" href="#v8_class_v8_defaultdeserializer" id="v8_class_v8_defaultdeserializer">#</a></span></h3>
<!--
added: v8.0.0
-->
<p>A subclass of <a href="#v8_class_v8_deserializer"><code>Deserializer</code></a> corresponding to the format written by
<a href="#v8_class_v8_defaultserializer"><code>DefaultSerializer</code></a>.</p>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>

